<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module MonitorMixin - monitor: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#module-MonitorMixin-label-Examples">Examples</a>
    <li><a href="#module-MonitorMixin-label-Simple+object.extend">Simple object.extend</a>
    <li><a href="#module-MonitorMixin-label-Simple+Class+include">Simple Class include</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li class="calls-super" ><a href="#method-c-extend_object">::extend_object</a>
    <li class="calls-super" ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-mon_check_owner">#mon_check_owner</a>
    <li ><a href="#method-i-mon_enter">#mon_enter</a>
    <li ><a href="#method-i-mon_exit">#mon_exit</a>
    <li ><a href="#method-i-mon_initialize">#mon_initialize</a>
    <li ><a href="#method-i-mon_locked-3F">#mon_locked?</a>
    <li ><a href="#method-i-mon_owned-3F">#mon_owned?</a>
    <li ><a href="#method-i-mon_synchronize">#mon_synchronize</a>
    <li ><a href="#method-i-mon_try_enter">#mon_try_enter</a>
    <li ><a href="#method-i-new_cond">#new_cond</a>
    <li ><a href="#method-i-synchronize">#synchronize</a>
    <li ><a href="#method-i-try_mon_enter">#try_mon_enter</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-MonitorMixin">
    <h1 id="module-MonitorMixin" class="module">
      module MonitorMixin
    </h1>

    <section class="description">
    
<p>In concurrent programming, a monitor is an object or module intended to be used safely by more than one thread. The defining characteristic of a monitor is that its methods are executed with mutual exclusion. That is, at each point in time, at most one thread may be executing any of its methods. This mutual exclusion greatly simplifies reasoning about the implementation of monitors compared to reasoning about parallel code that updates a data structure.</p>

<p>You can read more about the general principles on the Wikipedia page for <a href="https://en.wikipedia.org/wiki/Monitor_%28synchronization%29">Monitors</a>.</p>

<h2 id="module-MonitorMixin-label-Examples">Examples<span><a href="#module-MonitorMixin-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h3 id="module-MonitorMixin-label-Simple+object.extend">Simple object.extend<span><a href="#module-MonitorMixin-label-Simple+object.extend">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;monitor.rb&#39;</span>

<span class="ruby-identifier">buf</span> = []
<span class="ruby-identifier">buf</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">MonitorMixin</span>)
<span class="ruby-identifier">empty_cond</span> = <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">new_cond</span>

<span class="ruby-comment"># consumer</span>
<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">start</span> <span class="ruby-keyword">do</span>
  <span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
      <span class="ruby-identifier">empty_cond</span>.<span class="ruby-identifier">wait_while</span> { <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">empty?</span> }
      <span class="ruby-identifier">print</span> <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">shift</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-comment"># producer</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">gets</span>
  <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">line</span>)
    <span class="ruby-identifier">empty_cond</span>.<span class="ruby-identifier">signal</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>The consumer thread waits for the producer thread to push a line to buf while <code>buf.empty?</code>. The producer thread (main thread) reads a line from ARGF and pushes it into buf then calls <code>empty_cond.signal</code> to notify the consumer thread of new data.</p>

<h3 id="module-MonitorMixin-label-Simple+Class+include">Simple Class include<span><a href="#module-MonitorMixin-label-Simple+Class+include">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;monitor&#39;</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">SynchronizedArray</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Array</span>

  <span class="ruby-identifier">include</span> <span class="ruby-constant">MonitorMixin</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
    <span class="ruby-keyword">super</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">alias</span> <span class="ruby-value">:old_shift</span> <span class="ruby-value">:shift</span>
  <span class="ruby-keyword">alias</span> <span class="ruby-value">:old_unshift</span> <span class="ruby-value">:unshift</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">shift</span>(<span class="ruby-identifier">n</span>=<span class="ruby-value">1</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
      <span class="ruby-keyword">self</span>.<span class="ruby-identifier">old_shift</span>(<span class="ruby-identifier">n</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">unshift</span>(<span class="ruby-identifier">item</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
      <span class="ruby-keyword">self</span>.<span class="ruby-identifier">old_unshift</span>(<span class="ruby-identifier">item</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># other methods ...</span>
<span class="ruby-keyword">end</span>
</pre>

<p><code>SynchronizedArray</code> implements an Array with synchronized access to items. This Class is implemented as subclass of Array which includes the <a href="MonitorMixin.html"><code>MonitorMixin</code></a> module.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-extend_object" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">extend_object</span><span
                                class="method-args">(obj)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="extend_object-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 152</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">extend_object</span>(<span class="ruby-identifier">obj</span>)
  <span class="ruby-keyword">super</span>(<span class="ruby-identifier">obj</span>)
  <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">__send__</span>(<span class="ruby-value">:mon_initialize</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(...)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Use <code>extend MonitorMixin</code> or <code>include MonitorMixin</code> instead of this constructor.  Have look at the examples above to understand how to use this module.</p>
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 222</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-operator">...</span>)
  <span class="ruby-keyword">super</span>
  <span class="ruby-identifier">mon_initialize</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-mon_enter" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mon_enter</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Enters exclusive section.</p>

                              <div class="method-source-code" id="mon_enter-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 169</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mon_enter</span>
  <span class="ruby-ivar">@mon_data</span>.<span class="ruby-identifier">enter</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-mon_exit" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mon_exit</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Leaves exclusive section.</p>

                              <div class="method-source-code" id="mon_exit-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 176</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mon_exit</span>
  <span class="ruby-identifier">mon_check_owner</span>
  <span class="ruby-ivar">@mon_data</span>.<span class="ruby-identifier">exit</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-mon_locked-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mon_locked?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if this monitor is locked by any thread</p>

                              <div class="method-source-code" id="mon_locked-3F-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 184</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mon_locked?</span>
  <span class="ruby-ivar">@mon_data</span>.<span class="ruby-identifier">mon_locked?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-mon_owned-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mon_owned?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if this monitor is locked by current thread.</p>

                              <div class="method-source-code" id="mon_owned-3F-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 191</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mon_owned?</span>
  <span class="ruby-ivar">@mon_data</span>.<span class="ruby-identifier">mon_owned?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-mon_synchronize" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mon_synchronize</span><span
                                class="method-args">(&amp;b)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Enters exclusive section and executes the block.  Leaves the exclusive section automatically when the block exits.  See example under <code>MonitorMixin</code>.</p>

                              <div class="method-source-code" id="mon_synchronize-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 200</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mon_synchronize</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>)
  <span class="ruby-ivar">@mon_data</span>.<span class="ruby-identifier">synchronize</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="MonitorMixin.html#method-i-synchronize">synchronize</a>
                            </div>

                          </div>

                  <div id="method-i-mon_try_enter" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mon_try_enter</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Attempts to enter exclusive section.  Returns <code>false</code> if lock fails.</p>

                              <div class="method-source-code" id="mon_try_enter-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 160</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mon_try_enter</span>
  <span class="ruby-ivar">@mon_data</span>.<span class="ruby-identifier">try_enter</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="MonitorMixin.html#method-i-try_mon_enter">try_mon_enter</a>
                            </div>

                          </div>

                  <div id="method-i-new_cond" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new_cond</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new <a href="MonitorMixin/ConditionVariable.html"><code>MonitorMixin::ConditionVariable</code></a> associated with the <a href="Monitor.html"><code>Monitor</code></a> object.</p>

                              <div class="method-source-code" id="new_cond-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 209</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">new_cond</span>
  <span class="ruby-keyword">unless</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@mon_data</span>)
    <span class="ruby-identifier">mon_initialize</span>
    <span class="ruby-ivar">@mon_initialized_by_new_cond</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">return</span> <span class="ruby-constant">ConditionVariable</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@mon_data</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-synchronize" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">synchronize</span><span
                                class="method-args">(&amp;b)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="MonitorMixin.html#method-i-mon_synchronize">mon_synchronize</a>
                            </div>
                          </div>

                  <div id="method-i-try_mon_enter" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">try_mon_enter</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>For backward compatibility</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="MonitorMixin.html#method-i-mon_try_enter">mon_try_enter</a>
                            </div>
                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-mon_check_owner" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mon_check_owner</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="mon_check_owner-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 241</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mon_check_owner</span>
  <span class="ruby-ivar">@mon_data</span>.<span class="ruby-identifier">mon_check_owner</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-mon_initialize" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mon_initialize</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Initializes the <a href="MonitorMixin.html"><code>MonitorMixin</code></a> after being included in a class or when an object has been extended with the <a href="MonitorMixin.html"><code>MonitorMixin</code></a></p>

                              <div class="method-source-code" id="mon_initialize-source">
            <pre><span class="ruby-comment"># File monitor/lib/monitor.rb, line 229</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mon_initialize</span>
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@mon_data</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@mon_initialized_by_new_cond</span>)
      <span class="ruby-keyword">return</span> <span class="ruby-comment"># already initialized.</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@mon_data_owner_object_id</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">object_id</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ThreadError</span>, <span class="ruby-string">&quot;already initialized&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@mon_data</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Monitor</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-ivar">@mon_data_owner_object_id</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">object_id</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

